package com.whkjdx.examtool.web;

import com.whkjdx.examtool.entity.Question;
import com.whkjdx.examtool.service.QuestionService;
import com.whkjdx.examtool.web.request.ExamRequest;
import com.whkjdx.examtool.web.request.ExamResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author: xucong
 * @Date: 19:02 2022/1/31
 * @Description:
 * @Version v1.0
 */
@Slf4j
@Api(tags = "v1考试")
@RequestMapping("v1")
@RestController
public class QuestionV1Controller {

    @Autowired
    QuestionService questionService;

    @GetMapping("/createIndex")
    public String createIndex(){
        questionService.createIndex();
        return "success";
    }

    @ApiOperation("查询题目")
    @PostMapping("/queryQuestion")
    String queryQuestion(){
        questionService.quertQuestion();
        return "success";
    }

    @GetMapping("/deleteAll")
    public String deleteAll(){
        questionService.deleteAll();
        return "success";
    }

    @GetMapping("/search")
    public List<Question> search(String keyword){
        List<Question> search = questionService.search(keyword);
        return search;
    }

    @PostMapping("/exam")
    public ExamResponse exam(@RequestBody ExamRequest request){
        questionService.exam(request);
        ExamResponse examResponse = new ExamResponse();
        examResponse.setMsg("一键答题考试完成");
        return examResponse;
    }
}
